package com.tocea.formation.library;

import com.insta.achilog.dal.BookRequest;
import com.tocea.formation.exceptions.NotEnoughtExemplaireException;


public class Exemplaire implements IExemplaire
{
    private IBook book;
    private int nb;
    private BookRequest BookR =  new BookRequest();
    

    public Exemplaire(IBook book) {
        
        super();
        this.book = book;
        this.nb = 0;
    }
    
    public Exemplaire(IBook book, int nb) {
    
        super();
        this.book = book;
        this.nb = nb;
    }

    public IBook getBook() {
    
        return book;
    }
    
    public int getNbExemplaires() {
    
        return nb;
    }
    
    public void addExemplaire(int _nb) {
    
    	nb += _nb;
    	BookR.setNbExemplaire(book.getAuthor(), book.getAuthor(), nb);
    }
    
    public void removeExemplaire(int _nb) throws NotEnoughtExemplaireException {
        if (nb - _nb < 0) throw new NotEnoughtExemplaireException("");
        else {
            nb -= _nb;
            BookR.removeExemplaire(book.getAuthor(), book.getName(), nb);     	
        }
        
    }
    
}
